package br.ufms.odontologico.bo;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;

import br.ufms.odontologico.model.Atendimento;
import br.ufms.odontologico.model.Cliente;

@ManagedBean
@ViewScoped
public class AtendimentoBO  extends GenericBO<Atendimento> {

	@SuppressWarnings("unchecked")
	public List<Atendimento> listByCliente(Cliente cli) {
		EntityTransaction t = getEm().getTransaction();
		List<Atendimento> res = null;
		try{
			t.begin();
			Query q = getEm().createQuery("from Atendimento where cliente = ? order by dataHora desc");
			q.setParameter(1, cli);
			res = (List<Atendimento>)q.getResultList();
		}catch (Exception e) {
			e.printStackTrace();
			t.rollback();
		}
		return res;
	}
	
	
}
